package com.hecore.lagou.work.entity;

import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * @Author: hecore
 * @Date: 2020/10/18 23:36
 * @Description: 排序Bean 实现序列化接口
 */

public class SortNumBean implements WritableComparable<SortNumBean> {

    /**
     * 1.11 序列化方法
     * @param output
     * @throws IOException
     */
    public void write(DataOutput output) throws IOException {
        output.writeLong(num);
        output.writeLong(sortKey);
    }

    /**
     * 1.12 反序列化方法
     * @param input
     * @throws IOException
     */
    public void readFields(DataInput input) throws IOException {
        this.num=input.readLong();
        this.sortKey=input.readLong();
    }

    /**
     * 1.13 比较方法
     * @param o
     * @return
     */
    public int compareTo(SortNumBean o) {
        int result;
        // 按照数字⼤⼩，正序排列
        if (num > o.getNum()) {
            result = 1;
        }else if (num < o.getNum()) {
            result = -1;
        }else {
            // 数值相等,当前场景不存在,如果存在不处理即可
            result = 0;
        }
        return result;
    }


    /**
     * 1.2 attribute set
     */

    /**
     * 排序key
     */
    private long sortKey;

    /**
     * 当前数字数值
     */
    private long num;

    /**
     * 1.31  no param contractor
     */
    public SortNumBean() {
    }

    /**
     * 1.32 all param contractor
     * @param sortKey
     * @param num
     */
    public SortNumBean(long sortKey, long num) {
        this.sortKey = sortKey;
        this.num = num;
    }

    @Override
    public String toString() {
        return  sortKey +"\t"+
                num ;
    }

    /**
     * 1.33 toString
     * @return
     */


    public long getSortKey() {
        return sortKey;
    }

    public void setSortKey(long sortKey) {
        this.sortKey = sortKey;
    }

    public long getNum() {
        return num;
    }

    public void setNum(long num) {
        this.num = num;
    }


}
